﻿Imports System.IO

Public Class Form1

    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpszCommand As String, ByVal lpszReturnString As String, ByVal cchReturnLength As Integer, ByVal hwndCallback As Integer) As Integer ' Danke an Dieter Otter

    Public Function MP3_Play(ByVal sFile As String, ByVal sAlias As String) As Boolean ' Danke an Dieter Otter

        If mciSendString("open " & Chr(34) & sFile & Chr(34) & " type MPEGVideo alias " & sAlias, 0, 0, 0) = 0 Then
            If mciSendString("play " & sAlias & " from 0", 0, 0, 0) = 0 Then
                Return (True)
            End If
        End If
    End Function

    Public Sub MP3_Stop(ByVal sAlias As String) ' Danke an Dieter Otter

        mciSendString("stop " & sAlias, 0, 0, 0)
        mciSendString("close " & sAlias, 0, 0, 0)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MP3_Play("memories.mp3", "memories") ' Spielt die Musik ab
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        MP3_Stop("memories") ' Stopt die Musik
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim fs As New FileStream(My.Computer.FileSystem.CurrentDirectory & "/memories.mp3", FileMode.Create, FileAccess.Write)
        Dim wr As New BinaryWriter(fs)
        wr.Write(My.Resources.memories)

        wr.Close()
        fs.Close()
    End Sub
End Class
